<?php require_once('../../Connections/agriculture.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE message SET message_reply=%s WHERE message_id=%s",
                       GetSQLValueString($_POST['textarea'], "text"),
                       GetSQLValueString($_POST['hiddenField'], "int"));

  mysql_select_db($database_agriculture, $agriculture);
  $Result1 = mysql_query($updateSQL, $agriculture) or die(mysql_error());

  $updateGoTo = "bbsadmin.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  echo '<script language="javascript">alert("回复成功!");</script>>';
  echo "<meta http-equiv=refresh content='0;url=bbsadmin.php'>";
}

$colname_replyRecordset1 = "-1";
if (isset($_GET['id'])) {
  $colname_replyRecordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_agriculture, $agriculture);
$query_replyRecordset1 = sprintf("SELECT * FROM message WHERE message_id = %s", $colname_replyRecordset1);
$replyRecordset1 = mysql_query($query_replyRecordset1, $agriculture) or die(mysql_error());
$row_replyRecordset1 = mysql_fetch_assoc($replyRecordset1);
$totalRows_replyRecordset1 = mysql_num_rows($replyRecordset1);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>回复留言</title>
</head>

<body>
<p><a href="bbsadmin.php">返回</a></p>
<p>留言<?php echo $row_replyRecordset1['message_id']; ?></p>
<p>时间<?php echo $row_replyRecordset1['message_time']; ?></p>
<p>发布者<?php echo $row_replyRecordset1['message_poster']; ?></p>
<p>标题<?php echo $row_replyRecordset1['message_title']; ?></p>
<p>内容<?php echo $row_replyRecordset1['message_content']; ?></p>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <label>回复内容
  <textarea name="reply" id="reply"></textarea>
  </label>
  <input name="hiddenField" type="hidden" value="<?php echo $row_replyRecordset1['message_id']; ?>" />
  <p>
    <input type="submit" name="Submit" value="提交"  onclick="return checkForm(form1)"/>
    <label>
    <input type="reset" name="Submit2" value="重置" />
    </label>
  </p>
  <input type="hidden" name="MM_update" value="form1">
</form>

<script language="javascript">
function checkForm(){
if(!(form1.reply.value)){
alert("回复内容不能为空!");
return false;
}
return true;
}
</script>

</body>
</html>
<?php
mysql_free_result($replyRecordset1);
?>
